﻿using System;
using System.ComponentModel;
using TypeBuilderFx.Core;
using TypeBuilderFx.Core.Emitters;

namespace TypeBuilderFx.SimpleConsoleApp
{
    /// <summary>Sample application showing a simple use of TypeBuilderFx.</summary>
    /// <remarks>This code is actually used as an example in the documentation.</remarks>
    public class Program
    {
        public interface ISalesItem : INotifyPropertyChanged
        {
            /// <summary>Identifyer of the item.</summary>
            Guid ItemID { get; set; }

            /// <summary>Name displayed on screen.</summary>
            string DisplayName { get; set; }

            /// <summary>Number of items sold.</summary>
            int Quantity { get; set; }

            /// <summary>Price of individual item.</summary>
            /// <remarks>Optional.</remarks>
            decimal? Price { get; set; }
        }

        /// <summary>Entry point to the sample application.</summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ISalesItem salesItem = PropertyHolderEmitter.GetFactory<ISalesItem>().Build();

            salesItem.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                Console.WriteLine("Property '{0}' has been changed", e.PropertyName);
            };

            salesItem.ItemID = Guid.NewGuid();
            salesItem.DisplayName = "Corn";
            salesItem.Quantity = 5;
            salesItem.Price = (decimal)5.95;
        }
    }
}